package com.mofang.powerdekorhelper.activity.mine;

import android.view.View;
import android.widget.EditText;

import com.mofang.powerdekorhelper.R;
import com.mofang.powerdekorhelper.activity.login.LoginActivity;
import com.mofang.powerdekorhelper.base.MvpActivity;
import com.mofang.powerdekorhelper.model.ResultMessage2;
import com.mofang.powerdekorhelper.persenter.ChangeAccountPresenter;
import com.mofang.powerdekorhelper.utils.SharePerforenceUtils;
import com.mofang.powerdekorhelper.utils.T;
import com.mofang.powerdekorhelper.view.ChangeAccountView;
import com.mofang.powerdekorhelper.witget.TitleBar;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by luofei on 2017/8/17 0017.
 */

public class ChangeAccountActivity extends MvpActivity<ChangeAccountView, ChangeAccountPresenter> implements ChangeAccountView {

    @BindView(R.id.change_account_titlebar)
    TitleBar mTitleBar;

    @BindView(R.id.change_account_edit)
    EditText accountEdit;

    String userAccount;
    String userPhone;
    int userId;

    @Override
    public ChangeAccountPresenter initPresenter() {
        return new ChangeAccountPresenter();
    }

    @Override
    public void initView() {
        inflateLayout(R.layout.activity_change_account_layout);
        initTitleBarWithback(mTitleBar, R.string.change_acount);
    }

    @Override
    public void initData() {
        userId = SharePerforenceUtils.getInstance(this).getUserID();
        userAccount = SharePerforenceUtils.getInstance(this).getUserName();
        userPhone = SharePerforenceUtils.getInstance(this).getPhone();
        if (!userPhone.equals(userAccount)) {
            accountEdit.setText(userAccount);
        }

    }

    @OnClick({R.id.change_account_btn})
    void myOnclick(View view) {
        switch (view.getId()) {
            case R.id.change_account_btn:
                if (!accountEdit.getText().toString().equals("")) {
                    presenter.getChangeAccountResult(userId, accountEdit.getText().toString());
                } else {
                    T.showShort(this, "请输入新的账号");
                }
                break;
        }
    }

    @Override
    public void setResult(ResultMessage2 message) {
        SharePerforenceUtils.getInstance(this).setUserName("");
        toActivity(this, LoginActivity.class);
        finish();
    }

    @Override
    public void showProgress() {

    }

    @Override
    public void hideProgress() {

    }

    @Override
    public void toast(CharSequence s) {

        T.showShort(this, s);
    }

    @Override
    public void toast(int id) {

    }

    @Override
    public void showNullLayout() {

    }

    @Override
    public void hideNullLayout() {

    }

    @Override
    public void showErrorLayout(View.OnClickListener listener) {

    }

    @Override
    public void hideErrorLayout() {

    }

    @Override
    public void onError(String errorInfo) {

    }
}
